/*
*
* 平面五角星缓冲区绘制
* R: 外接圆半径
*
 */
function Star_bufferInit(gl, R=0.5) {

    //创建位置
    var positions = [];

    //添加五个凸顶点
    for (var i = 0; i < 5; i++) {
        var angle = (90 + i * 72) * (Math.PI / 180);

        var x = R * Math.cos(angle);
        var z = R * Math.sin(angle);

        const newTria = [x, 0, z];
        positions = positions.concat(newTria);
    }

    //添加五个凹顶点
    var r = R * Math.sin(18 * Math.PI / 180) / Math.cos(36 * Math.PI / 180);
    for (var i = 0; i < 5; i++) {
        var angle = (54 + i * 72) * (Math.PI / 180);

        var x = r * Math.cos(angle);
        var z = r * Math.sin(angle);

        const newTria = [x, 0, z];
        positions = positions.concat(newTria);
    }

    const positionBuf = gl.createBuffer();
    gl.bindBuffer(gl.ARRAY_BUFFER, positionBuf);
    gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(positions), gl.STATIC_DRAW);

    //创建颜色
    const starcolor = [0.8, 0.2, 0.5, 1.0];

    var faceColors = [];

    for (var i = 0; i < 10; i++) {
        faceColors = faceColors.concat(starcolor);
    }

    const colorBuf = gl.createBuffer();
    gl.bindBuffer(gl.ARRAY_BUFFER, colorBuf);
    gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(faceColors), gl.STATIC_DRAW);

    //创建面单元
    var surfaces = [
        0, 5, 6,
        1, 6, 7,
        2, 7, 8,
        3, 8, 9,
        4, 9, 5,

        5, 6, 7,
        5, 7, 8,
        5, 8, 9,
    ];

    const surfaceBuf = gl.createBuffer();
    gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, surfaceBuf);
    gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(surfaces), gl.STATIC_DRAW);

    return {
        position: positionBuf,
        color: colorBuf,
        surface: surfaceBuf,
        drawmode: gl.TRIANGLES,
        drawcount: 24,
        transparent: false,
    };
}